<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\file\FileInput;
use yii\web\JsExpression;
use common\models\business\BusinessInspection;
/* @var $this yii\web\View */
/* @var $model common\models\business\BusinessInspection */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="row">
    <div class="col-lg-12">
        <section class="panel">
        <div class="panel-body">
            <div class="adv-table editable-table ">
                <div class="business-inspection-form">
                    <?php $form = ActiveForm::begin([
                        'options' => ['class' => 'form-horizontal','enctype' => 'multipart/form-data'],
                        'fieldConfig' => [
                            'template' => "<div class='col-xs-3 col-sm-2 text-right'>{label}</div><div class='col-xs-9 col-sm-7'>{input}</div><div class='col-xs-12 col-xs-offset-3 col-sm-3 col-sm-offset-0'>{error}</div>",
                        ]
                    ]); ?>




                        <div class="form-group">
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-length">总长</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[length]" id="businessinspection-length" class="form-control" value="<?=$model['length']?>" maxlength="255" aria-invalid="false">
                            </div>
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-width">胸围</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[width]" id="businessinspection-width" class="form-control" value="<?=$model['width']?>" maxlength="255" aria-invalid="false">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-activelevel">精神</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[activelevel]" id="businessinspection-activelevel" class="form-control" value="<?=$model['activelevel']?>" maxlength="255" aria-invalid="false">
                            </div>
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-haircolor">毛色</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[haircolor]" id="businessinspection-haircolor" class="form-control" value="<?=$model['haircolor']?>" maxlength="255" aria-invalid="false">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-foodintake">饮食</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[foodintake]" id="businessinspection-foodintake" class="form-control" value="<?=$model['foodintake']?>" maxlength="255" aria-invalid="false">
                            </div>
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-shit">大便</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[shit]" id="businessinspection-shit" class="form-control" value="<?=$model['shit']?>" maxlength="255" aria-invalid="false">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-breath">呼吸</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[breath]" id="businessinspection-breath" class="form-control" value="<?=$model['breath']?>" maxlength="255" aria-invalid="false">
                            </div>
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-temperature">体温</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[temperature]" id="businessinspection-temperature" class="form-control" value="<?=$model['temperature']?>" maxlength="255" aria-invalid="false">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-cleanpen">清圈</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[cleanpen]" id="businessinspection-cleanpen" class="form-control" value="<?=$model['cleanpen']?>" maxlength="255" aria-invalid="false">
                            </div>
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-disinfection">消毒</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[disinfection]" id="businessinspection-disinfection" class="form-control" value="<?=$model['disinfection']?>" maxlength="255" aria-invalid="false">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-urine">尿色</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[urine]" id="businessinspection-urine" class="form-control" value="<?=$model['urine']?>" maxlength="255" aria-invalid="false">
                            </div>
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-pen_temperature">环境温度</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[pen_temperature]" id="businessinspection-pen_temperature" class="form-control" value="<?=$model['pen_temperature']?>" maxlength="255" aria-invalid="false">
                            </div>
                        </div>


                        <div class="form-group">
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-situation">体侧状态</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[situation]" id="businessinspection-situation" class="form-control" value="<?=$model['situation']?>" maxlength="255" aria-invalid="false">
                            </div>
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-feed">食料情况</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[feed]" id="businessinspection-feed" class="form-control" value="<?=$model['feed']?>" maxlength="255" aria-invalid="false">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-weight">体重</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[weight]" id="businessinspection-weight" class="form-control" value="<?=$model['weight']?>" maxlength="255" aria-invalid="false">
                            </div>
                            <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businessinspection-season">季节</label></div>
                            <div class="col-md-1 col-lg-2">
                                <input type="text" name="BusinessInspection[season]" id="businessinspection-season" class="form-control" value="<?=$model['season']?>" maxlength="255" aria-invalid="false">
                            </div>
                        </div>

                        <?php if($model->pig->liveryperson) {?>
                            <?= $form->field($model->pig->liveryperson, 'name')->textInput(['maxlength' => true,'disabled'=>true])->label('代养农户') ?>
                        <?php }?>
                        <?= $form->field($model, 'business_personid')->widget(\kartik\select2\Select2::className(), [
                            'options' => ['placeholder' => '请输入巡检人员名称 ...'],
                            'initValueText'=>!$model->person?'':$model->person->name,
                            'pluginOptions' => [
                                'allowClear' => true,
                                'minimumInputLength' => 1,//重要
                                'language' => [
                                    'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
                                ],
                                'ajax' => [
                                    'url' => '/business/search/search-person',
                                    'dataType' => 'json',
                                    'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                                    'cache' => true
                                ],
                                'width' => '400px',
                                'escapeMarkup' => new JsExpression('function (markup) { return markup;}'),
                                'templateResult' => new JsExpression('function(res) { return res.text;}'),
                                'templateSelection' => new JsExpression('function (res) { return res.text;}'),
                            ],
                        ])->label('巡检员');
                        ?>


                        <?= $form->field($model, 'pigid')->widget(\kartik\select2\Select2::className(), [
                            'options' => ['placeholder' => '请输入仔猪编号名称 ...'],
                            'initValueText'=>!$model->pig?'':$model->pig->no,
                            'pluginOptions' => [
                                'allowClear' => true,
                                'minimumInputLength' => 1,//重要
                                'language' => [
                                    'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
                                ],
                                'ajax' => [
                                    'url' => '/business/search/search-pig',
                                    'dataType' => 'json',
                                    'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                                    'cache' => true
                                ],
                                'width' => '400px',
                                'escapeMarkup' => new JsExpression('function (markup) { return markup;}'),
                                'templateResult' => new JsExpression('function(res) { return res.text;}'),
                                'templateSelection' => new JsExpression('function (res) { return res.text;}'),
                            ],
                        ]);
                        ?>

                        <?= $form->field($model, 'healthy')->textInput(['maxlength' => true]) ?>

                        <?= $form->field($model, 'status')->dropDownList(BusinessInspection::$statues) ?>

                        <?= $form->field($model, 'remark')->textarea(['maxlength' => true]) ?>

                        <?= $form->field($model, 'pigpen')->textInput(['maxlength' => true]) ?>

                        <?= $form->field($model, 'pigpen_desc')->textarea(['maxlength' => true]) ?>

                        <?= $form->field($model, 'feed_desc')->textarea(['maxlength' => true]) ?>


                        <?= $form->field($model, 'pigpen_photo[]')->widget(FileInput::classname(), [
                            'options' => ['multiple' => true],
                            'pluginOptions' => [
                                // 需要预览的文件格式
                                'previewFileType' => 'image',
                                // 预览的文件
                                'initialPreview' => \common\components\Upload::checkGetUrl($model->pigpen_photo,true,'pigpen_photo'),
                                // 需要展示的图片设置，比如图片的宽度等
                                'initialPreviewConfig' => \common\components\Upload::initialPreviewConfig($model,'pigpen_photo',BusinessInspection::tableName(),$model->id),
                                // 是否展示预览图
                                'initialPreviewAsData' => true,
                                'showUpload' => false,
                                'overwriteInitial' => false,
                            ],
                        ]); ?>


                        <?= $form->field($model, 'feed_photo[]')->widget(FileInput::classname(), [
                            'options' => ['multiple' => true],
                            'pluginOptions' => [
                                // 需要预览的文件格式
                                'previewFileType' => 'image',
                                'showRemove' => true,
                                // 预览的文件
                                'initialPreview' => \common\components\Upload::checkGetUrl($model->feed_photo,true,'feed_photo'),
                                // 需要展示的图片设置，比如图片的宽度等
                                'initialPreviewConfig' => \common\components\Upload::initialPreviewConfig($model,'feed_photo',BusinessInspection::tableName(),$model->id),
                                // 是否展示预览图
                                'initialPreviewAsData' => true,
                                'showUpload' => false,
                                'overwriteInitial' => false,
                            ],
                        ]); ?>

                        <?= $form->field($model, 'pigphoto[]')->widget(FileInput::classname(), [
                            'options' => ['multiple' => true],
                            'pluginOptions' => [
                                // 需要预览的文件格式
                                'previewFileType' => 'image',
                                // 预览的文件
                                'initialPreview' => \common\components\Upload::checkGetUrl($model->pigphoto,true,'pigphoto'),
                                // 需要展示的图片设置，比如图片的宽度等
                                'initialPreviewConfig' => \common\components\Upload::initialPreviewConfig($model,'pigphoto',BusinessInspection::tableName(),$model->id),
                                // 是否展示预览图
                                'initialPreviewAsData' => true,
                                'showUpload' => false,
                                'overwriteInitial' => false,
                            ],
                        ]); ?>


                     <?= Html::activeHiddenInput($model,'createtime',array('value'=>strtotime(date('Y-m-d H:i:s')))) ?>

                    <div class="form-group">
                        <?= Html::submitButton($model->isNewRecord ? '确认提交' : '确认更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
                    </div>
                    <?php ActiveForm::end(); ?>
                </div>
            </div>
        </div>
    </section>
</div>
</div>

<script>
    <?php $this->beginBlock('js_end') ?>
        $('.field-businessinspection-pigpen_photo').on('filesorted', function(event, params) {
            var data = [];
            $.each(params.stack,function(k,v){
                data.push({'path':v.caption,'table':v.extra.table,'field':v.extra.field,'id':v.extra.id,'idname':v.extra.idname});
            })
            $.post('/site/sortfile',{'data':data},function(res){
                console.log(res)
            });
            console.log('File sorted ', params.previewId, params.oldIndex, params.newIndex, params.stack);
        });

        $('.field-businessinspection-feed_photo').on('filesorted', function(event, params) {
            var data = [];
            $.each(params.stack,function(k,v){
                data.push({'path':v.caption,'table':v.extra.table,'field':v.extra.field,'id':v.extra.id,'idname':v.extra.idname});
            })
            $.post('/site/sortfile',{'data':data},function(res){
                console.log(res)
            });
            console.log('File sorted ', params.previewId, params.oldIndex, params.newIndex, params.stack);
        });

        $('.field-businessinspection-pigphoto').on('filesorted', function(event, params) {
            var data = [];
            $.each(params.stack,function(k,v){
                data.push({'path':v.caption,'table':v.extra.table,'field':v.extra.field,'id':v.extra.id,'idname':v.extra.idname});
            })
            $.post('/site/sortfile',{'data':data},function(res){
                console.log(res)
            });
            console.log('File sorted ', params.previewId, params.oldIndex, params.newIndex, params.stack);
        });

    <?php $this->endBlock(); ?>
    <?php $this->registerJs($this->blocks['js_end'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
</script>